package rsj.service.report;

import com.alibaba.fastjson.JSON;
import com.rlyy.aibase.utils.base.TableNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import rsj.api.report.entity.CustomerProductReport;
import rsj.api.report.entity.CustomerProductReportDetail;
import rsj.api.report.entity.ReportParam;
import rsj.sql.customer.CustomerProductReportDao;
import rsj.sql.operlog.OperateLogDao;

import java.util.List;

/**
 * 客户接口报表
 *
 * @author yuanqinglong
 * @since 2021/7/22 9:12
 */
@Service
public class CustomerProductReportServiceImpl implements IReportService<CustomerProductReport, CustomerProductReportDetail, ReportParam> {




    @Autowired
    private CustomerProductReportDao customerProductReportDao;


    /**
     * 报告列表
     *
     * @param reportParam 报告参数
     * @return {@link List<CustomerProductReport>}
     */
    @Override
    public List<CustomerProductReport> reportList(ReportParam reportParam) {
        TableNode tableNode = customerProductReportDao.customerProductReportList(reportParam);
        List<CustomerProductReport> customerReports = JSON.parseArray(tableNode.toJson(), CustomerProductReport.class);
        customerReports.forEach(CustomerProductReport::calculateRate);
        return customerReports;
    }

    /**
     * 报告数
     *
     * @param reportParam 报告参数
     * @return int
     */
    @Override
    public int reportCount(ReportParam reportParam) {
        return customerProductReportDao.customerProductReportCount(reportParam).valueInt();
    }

    /**
     * 详细的列表
     *
     * @param reportParam 报告参数
     * @return {@link List<CustomerProductReportDetail>}
     */
    @Override
    public List<CustomerProductReportDetail> detailList(ReportParam reportParam) {
        TableNode reportDetailList = customerProductReportDao.customerProductReportDetailList(reportParam);
        List<CustomerProductReportDetail> customerProductReportDetails = JSON.parseArray(reportDetailList.toJson(), CustomerProductReportDetail.class);
        customerProductReportDetails.forEach(CustomerProductReportDetail::calculateRate);
        return customerProductReportDetails;
    }

    /**
     * 详细的计算
     *
     * @param reportParam 报告参数
     * @return int
     */
    @Override
    public int detailCount(ReportParam reportParam) {
        return customerProductReportDao.customerProductReportDetailCount(reportParam).valueInt();
    }



}
